import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-16
 * Time: 7:32
 */
class MyArray1<T>{
    public T[] array = (T[])new Object[3];
    //public T[] array = new T[3];
    public void setVal(int pos,T val){
        array[pos] = val;
    }
    public T getVal(int pos){
        return array[pos];
    }
    public T[] getArray(){
        return array;
    }
}
public class Test {
    public static void main(String[] args) {
        MyArray1<Integer>  myArray1 = new MyArray1<>();
        myArray1.setVal(0,1);
        Integer[] tmp = myArray1.getArray();
    }
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> hash = new HashSet<Character>();
        int n = s.length();
        int end = -1,ans = 0;
        for(int i = 0; i < n; i++){
            if(i != 0){
                hash.remove(s.charAt(i-1));
            }
            while(end < n-1 && !hash.contains(s.charAt(end+1))){
                end++;
                hash.add(s.charAt(end));
            }
            ans = Math.max(ans,end - i +1);
        }
        return ans;
    }
    public static void main1(String[] args) {
        String  s = "pwwkew";
        System.out.println(lengthOfLongestSubstring(s));
    }
}
